package com.wu.server.dao;

import com.wu.server.entity.Tag;
import com.wu.server.entity.Type;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

public interface NewTypeRepository extends JpaRepository<Type, Long> {
    @Query(value = "select * from jd_shop.type where " +
            "(jd_shop.type.id = ?1 or ?1 is null) and" +
            "(jd_shop.type.type_name like ?2 or ?2 is null) and" +
            "(jd_shop.type.type_sum between ?3 and ?4 or ?3 is null or ?4 is null) and" +
            "(jd_shop.type.type_sales between ?5 and ?6 or ?5 is null or ?6 is null)"
            , nativeQuery = true)
    Page<Type> findAllBy(String id, String typeName, String summary1, String summary2, String sales1,String sales2, Pageable pageable);

    // 删除商品
    @Transactional
    @Modifying
    @Query(value = "delete from jd_shop.type where id = ?1", nativeQuery = true)
    void deleteTypeById(int id);
}
